﻿using ControlHelper.Attributes;
using Creator.Core.Log; 
using System; 

namespace Creator.Core.Base
{
    /// <summary>
    /// 所有行为的基类
    /// </summary>
    public abstract class Behaviour : ILog
    {
        public Behaviour()
        {

        }
        /// <summary>
        /// 这个主要为了基类对象的引用(这个构造函数或许有更好的方式去实现)
        /// </summary>
        /// <param name="baseObject"></param>
        public Behaviour(BaseObject baseObject)
        {
            if (baseObject == null) return;
            BaseObject = baseObject;
            Id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
            BaseObjectId = baseObject.Id;
        }
        private long baseObjectId;
        public event Action<string,LogLevel > Log;

        
        public long Id { get; set; }
        [Hide]
        public long BaseObjectId { get; set; }
        [Hide]
        public BaseObject BaseObject { get; set; }
        [Hide]
        public bool Active { get; set; } = true;
        public abstract string Name { get; }

        public virtual void Init() { }
        /// <summary> 运行 </summary>
        /// <param name="deltaTime">时间间隔/时间增量</param>
        public virtual void Run(double deltaTime) { }
        public virtual void Stop() { }
        /// <summary>
        /// 在编辑窗口时，才会有用
        /// </summary>
        public virtual void OnEditor() { }
        /// <summary>
        /// 输出信息
        /// <para>levle:1.普通信息</para> 
        /// <para>levle:2.警告信息</para> 
        /// <para>levle:3.错误信息</para> 
        /// <para>levle:4.严重信息</para> 
        /// <para>levle:5.异常信息</para> 
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="levle"></param>
        protected virtual void ShowMsg(string msg, LogLevel levle =  LogLevel.Information)
        {
            Log?.Invoke(msg, levle);
        }

    }
}
